/**
 * Created by zhangyue on 2020/8/24.
 */



const H_class = function(obj){
    return `
<li><a href="class_detail.html?kid=${obj.id}"><img src="${obj.fengmian}" alt=""><h4>${obj.name}</h4>
                                <p><span>${obj.teacher}</span> ${obj.rs}人正在学习</p></a></li>
    `;
};

const H_teacher = function(obj){
    return `
    <li><a href="class_teacher.html?tid=${obj.id}">${obj.name}<span>></span></a></li>
    `;
};

const H_xuanke = function(obj){
    return `
       <li>
                                <h4 onclick="window.location.href='class_detail.html?kid=${obj.id}'">继续学习 ${obj.name}</h4>
                                <p>上课时间 ${obj.shijian}</p>
                            </li>
    `;
};


if(mydata.get('id') && mydata.get('id')!=""){
    document.getElementById('footer').innerHTML=`
          <a class="alla" href='class_list.html?type=shoucang'>我的收藏</a>
                                <a class="alla" href='class_list.html?type=xuanke'>我的选课</a>
                                <a onclick="_xiugai()" class="alla">修改密码</a>
                                <a onclick="_tuichu()" class="alla">退出登录</a>
        `;
}else{
    document.getElementById('footer').innerHTML=`
         <a href="landing.html">
                                    <span class="glyphicon glyphicon-user footer-landing">登录</span>
                                </a>
                                <a href="register.html">注册</a>
        `;
}


var _sousuo = function(){
    let str = window.prompt('请输入课程名称');
    if(str && str!=""){
        shuju.set('name',str);
        shuju.set('method','sousuo');
        shuju.getshuju('kecheng',{
            success:function(data){
                if(data.code==200){
                    window.location.href='class_detail.html?kid='+data.id;
                }else{
                    alert('没有这门课');
                }
            },
            error:function(e){
                alert('网络错误');
            }
        })
    }
};

const _tuichu = function(){
    localStorage.clear();
    window.location.href='index.html';
};


const _xiugai = function(){
    let str = window.prompt('请输入新密码');
    if(str && str!=""){
        shuju.set('id',mydata.get('id'));
        shuju.set('password',str);
        shuju.set('method','changemima');
        shuju.getshuju('user',{
            success:function(data){
                if(data.code==200){
                    alert('修改成功');
                }else{
                    alert('修改失败');
                }
            },
            error:function(e){
                alert('网络错误');
            }
        })
    }
};

